package com.wh.hotel.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.base.Preconditions;
import com.wh.common.annotation.ResultLog;
import com.wh.common.enums.MethodTypeEnum;
import com.wh.common.vo.Result;
import com.wh.hotel.enums.base.HotelOperateTypeEnum;
import com.wh.hotel.model.HotelPricingStrategy;
import com.wh.hotel.param.StatusChangeParam;
import com.wh.hotel.service.HotelPriceStrategyService;
import com.wh.hotel.vo.HotelPriceStrategyVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author luweije
 */
@RequestMapping("/hotel/price/strategy")
@RestController
@Slf4j
public class HotelPriceStrategyController {

    @Resource
    private HotelPriceStrategyService hotelPriceStrategyService;

    /**
     * 新增或修改定价策略
     *
     * @param hotelPriceStrategyVo
     * @return
     */
    @PostMapping("/save")
    @ResultLog(name = "HotelPriceStrategyController.savePriceStrategy", methodType = MethodTypeEnum.HTTP_UP)
    public Result<HotelPricingStrategy> savePriceStrategy(@RequestBody HotelPriceStrategyVo hotelPriceStrategyVo) {
        Preconditions.checkNotNull(hotelPriceStrategyVo.getStrategyName(), "策略名称不能空");
        Preconditions.checkNotNull(hotelPriceStrategyVo.getSuitRangePo(), "策略适用范围不能空");
        Preconditions.checkNotNull(hotelPriceStrategyVo.getValidTimePo(), "策略生效时间规则不能空");
        Preconditions.checkNotNull(hotelPriceStrategyVo.getPriceChangeVo(), "策略变价规则不能空");
        return Result.successResponse(hotelPriceStrategyService.savePriceStrategy(hotelPriceStrategyVo));
    }

    /**
     * 上下架定价策略
     *
     * @param statusChangeParam
     * @return
     */
    @PostMapping("/updateStrategyStatus")
    @ResultLog(name = "HotelPriceStrategyController.updateStrategyStatus", methodType = MethodTypeEnum.HTTP_UP)
    public Result<Boolean> updateStrategyStatus(@RequestBody StatusChangeParam statusChangeParam) {
        Preconditions.checkNotNull(statusChangeParam.getId(), "策略ID不能空");
        Preconditions.checkNotNull(HotelOperateTypeEnum.parse(statusChangeParam.getOperateType()), "操作类型不能空");
        return Result.successResponse(hotelPriceStrategyService.updateStrategyStatus(statusChangeParam));
    }

    /**
     * 查询定价策略列表
     *
     * @param hotelPriceStrategyVo
     * @return
     */
    @PostMapping("/list")
    @ResultLog(name = "HotelPriceStrategyController.list", methodType = MethodTypeEnum.HTTP_UP)
    public Result<IPage<HotelPriceStrategyVo> > list(@RequestBody HotelPriceStrategyVo hotelPriceStrategyVo) {
        return Result.successResponse(hotelPriceStrategyService.list(hotelPriceStrategyVo));
    }


    /**
     * 查询定价策略详情
     *
     * @param hotelPriceStrategyVo
     * @return
     */
    @PostMapping("/detail")
    @ResultLog(name = "HotelPriceStrategyController.detail", methodType = MethodTypeEnum.HTTP_UP)
    public Result<HotelPriceStrategyVo> detail(@RequestBody HotelPriceStrategyVo hotelPriceStrategyVo) {
        Preconditions.checkNotNull(hotelPriceStrategyVo.getId(), "策略ID不能空");
        return Result.successResponse(hotelPriceStrategyService.detail(hotelPriceStrategyVo));
    }
}
